// Simple_Expression.cpp: implementation of the Simple_Expression class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Expression.h"
#include "Simple_Expression.h"
#include "Additive_Expression.h"
#include "RelopNote.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Simple_Expression::Simple_Expression()
{
	m_pRelop = NULL;
}

Simple_Expression::~Simple_Expression()
{
	delete m_pRelop;
}

BOOL Simple_Expression::Interpret()
{
	CString strTemp;
	ComplierNote* pNote = new Additive_Expression;
	pNote->SetOwner(this);
	LeftNote(pNote);

	if(!pNote->Interpret())
	{
		this->ErrorInfo(pNote->ErrorInfo());
		return FALSE;
	}

	strTemp = AAnalyzer()->GetCurSymbol();
	if(strTemp.IsEmpty() || strTemp == _T(")") || strTemp == _T(";") || strTemp == _T(","))
		return TRUE;

	m_pRelop = new RelopNote;
	m_pRelop->SetOwner(this);
	if(!m_pRelop->Interpret())
	{
		this->ErrorInfo(m_pRelop->ErrorInfo());
		AAnalyzer()->MovePrevSymbol();
		return FALSE;
	}

	pNote = new Additive_Expression;
	pNote->SetOwner(this);
	RightNote(pNote);

	if(!pNote->Interpret())
	{
		this->ErrorInfo(pNote->ErrorInfo());
		return FALSE;
	}
	return TRUE;
}

Variable Simple_Expression::Execute()
{
	if(m_pRelop != NULL)
	{
		return m_pRelop->Execute();
	}
	else
	{
		return LeftNote()->Execute();
	}
}